package com.dc.designPattern._2_factory._1_simplefactory.order;

import com.dc.designPattern._2_factory._1_simplefactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * Description: 披萨订单
 * @author: gdc
 * @date: 2021/3/7
 * @version 1.0
 */
public class OrderPizza {

	//public OrderPizza() {
	//	/**
	//	 * 披萨信息
	//	 */
	//	Pizza pizza;
	//
	//	do {
	//		String orderType = getType();
	//		if (orderType.equals("greek")) {
	//			pizza = new GreekPizza();
	//			pizza.setName(" 希腊披萨 ");
	//		} else if (orderType.equals("cheese")) {
	//			pizza = new CheesePizza();
	//			pizza.setName(" 奶酪披萨 ");
	//		} else if (orderType.equals("pepper")) {
	//			pizza = new PepperPizza();
	//			pizza.setName("胡椒披萨");
	//		} else {
	//			break;
	//		}
	//
	//		//输出pizza 制作过程
	//		pizza.execute();
	//	} while (true);
	//}

	/**
	 * 定义一个简单工厂对象
	 */
	SimpleFactory simpleFactory;
	Pizza pizza = null;

	public OrderPizza(SimpleFactory simpleFactory) {
		setFactory(simpleFactory);
	}

	public void setFactory(SimpleFactory simpleFactory) {
		this.simpleFactory = simpleFactory;
		do {
			//用户输入的
			String orderType = getType();
			pizza = this.simpleFactory.createPizza(orderType);

			if(pizza != null) {
				//订购成功，输出pizza
				pizza.execute();
			} else {
				System.out.println(" 订购披萨失败 ");
				break;
			}
		}while(true);
	}

	/**
	 * 可以获取客户希望订购的披萨种类
	 */
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类:");
			return strin.readLine();
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

}